package main

import (
	"encoding/json"
	"fmt"
	"log"
)

func main() {
	var movies = []Movie{
		{Title: "Casablanca", Year: 1942, Color: false, Actors: []string{"Humphrey Bogart", "Ingrid Bergman"}}, {Title: "Cool Hand Luke", Year: 1967, Color: true, Actors: []string{"Paul Newman"}}, {Title: "Bullitt", Year: 1968, Color: true, Actors: []string{"Steve McQueen", "Jacqueline Bisset"}}, // ... }

	}
	//该函数有两个额外的字符串参数用于表 示每一行输出的前缀和每一个层级的缩进：
	data, err := json.MarshalIndent(movies, "", " ")
	fmt.Printf("%s\n",data)
	fmt.Println(err)
	//fmt.Println("hhh")
	if err != nil { log.Fatalf("JSON marshaling failed: %s", err) }
	var titles []struct{ Title string }
	if err := json.Unmarshal(data, &titles); err != nil {
		log.Fatalf("JSON unmarshaling failed: %s", err) }
	fmt.Println(titles)
	//fmt.Printf("%s\n", data)
	//p:=new(per)
	//
	//add(p)


}
func add(p *per)  {
	p.name="huazi"
}

type per struct {
	age int
	name string
}

type Movie struct {
	Title string
	Year int `json:"released"`
	Color bool `json:"color,omitempty"`
	Actors []string
}
